// Avoid `console` errors in browsers that lack a console.
(function() {
  var method;
  var noop = function() {};
  var methods = [
    'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
    'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
    'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
    'timeStamp', 'trace', 'warn'
  ];
  var length = methods.length;
  var console = (window.console = window.console || {});

  while (length--) {
    method = methods[length];

    // Only stub undefined methods.
    if (!console[method]) {
      console[method] = noop;
    }
  }
}());

// Place any jQuery/helper plugins in here.

(function($, f) {
  function Typewriter(el, opts) {
    var t = this;
    t.opts = {};
    t.el = el;
    t.opts = $.extend(t.opts, opts);

    return {
      start: function() {
        $(".tx", t).html("");
        $(".tx").each(function() {
          var sNow = $(this);
          var time = 20;
          if (!sNow.attr("data-text")) {
            sNow.attr("data-text", $.trim(sNow.text()))
          }
          sNow.html("");
          var text = sNow.attr("data-text");
          var fh = ["@", "#", "$", "%", "^", "&", "*"];

          var appText = "";
          var appNu = 0;
          var whSt = setInterval(function() {
            if (appText.length < text.length) {
              appText += fh[1];
            }
            if (appText.length > 3 && appNu < text.length) {
              appText = appText.replace(appText[appNu], text[appNu]);
              appNu++;
            }

            sNow.text(appText);

            if (appNu == text.length) {
              clearInterval(whSt);
            }
          }, time);
        });
      }
    }
  }
  $.fn.typewriter = function(o) {
    return this.each(function(index) {
      var len = this.length;
      var me = $(this);
      var instance = new Typewriter(me, o);
      me.data('typewriter' + (len > 1 ? '-' + (index + 1) : ''), instance);
    });
  }

})(window.jQuery, false);

// String format
/**
* var ret = String.format("{0},{1}","abc","efg");
*/
String.format = function() {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    for ( var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
};